//*The wind blows in Nanjing Hangkonghangtian University,filling you with DETERMINATION
#include <bits/stdc++.h>
//use long long if necessary!
//use long long if necessary!
//use long long if necessary!
#define ll long long
#define pii pair<int,int>
using namespace std;
void read(int &n){
    int x=0,f=1;char ch=getchar();
    while (!(ch>='0'&&ch<='9')){if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    n=x*f;
}
//remember to clear!
int T;
const int N=2005;
int n,a[N];
bool b[N];
int maxn;
//faster than x=max(x,y)
inline void enmax(int &x,int y){
    if (x<y){
        x=y;
    }
}
void dfs(int depth){
    if (depth==n){
        int tot=0;
        for (int i=0;i<n;i++){
            int j=i-1;
            for (;j>=0;j--){
                if (b[j]==b[i])break;
            }
            if (a[i]==a[j])tot+=a[i];
        }
        enmax(maxn,tot);
        return;
    }
    dfs(depth+1);
    b[depth]=true;
    dfs(depth+1);
    b[depth]=false;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    read(T);
    while (T--){
        read(n);
        for (int i=0;i<n;i++){
            read(a[i]);
        }
        maxn=0;
        dfs(0);
        printf("%d\n",maxn);
    }
    return 0;
}
//use %lld if use long long!